home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Halma 1.1.source Folder / Halma ƒ / Shell ƒ / launch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  2.9 KB  |  111 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        launch.c
  4.  
  5. Purpose:    This module handles launching another application.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "launch.h"
  25. #include "file interface.h"
  26.  
  27. #define haveAUX() 0
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for launch.c                                                       */
  31.  
  32. void DoLaunch(Ptr theApp, short memCode );
  33. void PathNameFromDirID(long dirID, short vRefNum, Str255 fullPathName);
  34. void pstrcat(Str255 dst, Str255 src);
  35. void pstrinsert(Str255 dst, Str255 src);
  36.  
  37.  
  38. void LaunchDispatch(void)
  39. {
  40.     FSSpec                temp;
  41.  
  42.     GetSourceFile(&temp, FALSE, TRUE);
  43.     PathNameFromDirID(temp.parID, temp.vRefNum, temp.name);
  44.     DoLaunch((Ptr)temp.name,  0 );            /* launch the program */
  45. }
  46.  
  47. void DoLaunch(Ptr theApp, short memCode )
  48. {
  49.     struct {                /* temporary structure */
  50.         Ptr    appName;    /* the name of the launchee */
  51.         short    memUse;        /* config. param. see above Notes */
  52.         char    lc[2];            /* extended parameters */
  53.         long    extBlocLen;    /* # bytes in extension(6) */
  54.         short    fFlags;    /* Finder file info flags */
  55.         long    launchFlags;    /* bit 31,30==1 for sublaunch */
  56.     } LaunchRec;
  57.  
  58.     LaunchRec.appName = theApp;
  59.     LaunchRec.launchFlags = memCode;
  60.     asm {
  61.             lea    LaunchRec, A0
  62.             _Launch
  63.     }
  64. }
  65.  
  66. void pstrcat(Str255 dst, Str255 src)
  67. {
  68.     /* copy string in */
  69.     BlockMove(src + 1, dst + *dst + 1, *src);
  70.     /* adjust length byte */
  71.     *dst += *src;
  72. }
  73.  
  74. void pstrinsert(Str255 dst, Str255 src)
  75. {
  76.     /* make room for new string */
  77.     BlockMove(dst + 1, dst + *src + 1, *dst);
  78.     /* copy new string in */
  79.     BlockMove(src + 1, dst + 1, *src);
  80.     /* adjust length byte */
  81.     *dst += *src;
  82. }
  83.  
  84. void PathNameFromDirID(long dirID, short vRefNum, Str255 fullPathName)
  85. {
  86.     DirInfo    block;
  87.     Str255    directoryName;
  88.     OSErr    err;
  89.  
  90.     block.ioDrParID = dirID;
  91.     block.ioNamePtr = directoryName;
  92.     do
  93.     {
  94.         block.ioVRefNum = vRefNum;
  95.         block.ioFDirIndex = -1;
  96.         block.ioDrDirID = block.ioDrParID;
  97.         err = PBGetCatInfo(&block, FALSE);
  98.         if (haveAUX())
  99.         {
  100.             if (directoryName[1] != '/')
  101.                 pstrcat(directoryName, (StringPtr)"\p/");
  102.         }
  103.         else
  104.         {
  105.             pstrcat(directoryName, (StringPtr)"\p:");
  106.         }
  107.         pstrinsert(fullPathName, directoryName);
  108.     }
  109.     while (block.ioDrDirID != 2);
  110. }
  111.